From e2cd4cdb52ecdefeae4b451d7316ac8f82606a3f Mon Sep 17 00:00:00 2001 From: Felix Crux Date: Sun, 10 Jan 2016 14:47:02 -0500 Subject: [PATCH] Fix listing of untracked files to not include tracked but modified ones The logic in `sources/path.rs` that finds files that are untracked by the version control system was incorrectly including files that *are* tracked, but had been modified without the modification being committed to Git. This manifested itself as strange duplications of files (e.g. in `cargo package --list`), since they were listed once as tracked files, and once more as allegedly "untracked" ones. It also caused failures when trying to package the crate when files had been deleted, but the deletion was not yet committed to Git. Fixes #2199 --- src/cargo/sources/path.rs | 7 +++++-- tests/test_cargo_package.rs | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index 172fbe91d..91162a5fe 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -161,8 +161,11 @@ impl<'cfg> PathSource<'cfg> { opts.pathspec(suffix); } let statuses = try!(repo.statuses(Some(&mut opts))); - let untracked = statuses.iter().map(|entry| { - (join(&root, entry.path_bytes()), None) + let untracked = statuses.iter().filter_map(|entry| { + match entry.status() { + git2::STATUS_WT_NEW => Some((join(&root, entry.path_bytes()), None)), + _ => None + } }); 'outer: for (file_path, is_dir) in index_files.chain(untracked) { diff --git a/tests/test_cargo_package.rs b/tests/test_cargo_package.rs index 1a26ba359..290e46354 100644 --- a/tests/test_cargo_package.rs +++ b/tests/test_cargo_package.rs @@ -371,6 +371,32 @@ test!(package_git_submodule { assert!(from_utf8(&result.stdout).unwrap().contains(&format!("{} bar/Makefile", ARCHIVING))); }); +test!(no_duplicates_from_modified_tracked_files { + let root = paths::root().join("all"); + let p = git::repo(&root) + .file("Cargo.toml", r#" + [project] + name = "foo" + version = "0.0.1" + authors = [] + "#) + .file("src/main.rs", r#" + fn main() {} + "#); + p.build(); + File::create(p.root().join("src/main.rs")).unwrap().write_all(r#" + fn main() { println!("A change!"); } + "#.as_bytes()).unwrap(); + let mut cargo = ::cargo_process(); + cargo.cwd(p.root()); + assert_that(cargo.clone().arg("build"), execs().with_status(0)); + assert_that(cargo.arg("package").arg("--list"), + execs().with_status(0).with_stdout(&format!("\ +Cargo.toml +src/main.rs +"))); +}); + test!(ignore_nested { let cargo_toml = r#" [project] -- 2.30.2